package com.ruoyi.machine.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.machine.domain.SysSimDevice;
import com.ruoyi.machine.service.ISysSimDeviceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 自助设备Controller
 * 
 * @author laifolai
 * @date 2023-02-07
 */
@RestController
@RequestMapping("/machine/manage")
public class SysSimDeviceController extends BaseController
{
    @Autowired
    private ISysSimDeviceService sysSimDeviceService;

    /**
     * 查询自助设备列表
     */
    @PreAuthorize("@ss.hasPermi('machine:manage:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSimDevice sysSimDevice)
    {
        startPage();
        List<SysSimDevice> list = sysSimDeviceService.selectSysSimDeviceList(sysSimDevice);
        return getDataTable(list);
    }

    /**
     * 导出自助设备列表
     */
    @PreAuthorize("@ss.hasPermi('machine:manage:export')")
    @Log(title = "自助设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysSimDevice sysSimDevice)
    {
        List<SysSimDevice> list = sysSimDeviceService.selectSysSimDeviceList(sysSimDevice);
        ExcelUtil<SysSimDevice> util = new ExcelUtil<SysSimDevice>(SysSimDevice.class);
        util.exportExcel(response, list, "自助设备数据");
    }

    /**
     * 获取自助设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('machine:manage:query')")
    @GetMapping(value = "/{deviceId}")
    public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId)
    {
        return AjaxResult.success(sysSimDeviceService.selectSysSimDeviceByDeviceId(deviceId));
    }

    /**
     * 新增自助设备
     */
    @PreAuthorize("@ss.hasPermi('machine:manage:add')")
    @Log(title = "自助设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysSimDevice sysSimDevice)
    {
        return toAjax(sysSimDeviceService.insertSysSimDevice(sysSimDevice));
    }

    /**
     * 修改自助设备
     */
    @PreAuthorize("@ss.hasPermi('machine:manage:edit')")
    @Log(title = "自助设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysSimDevice sysSimDevice)
    {
        return toAjax(sysSimDeviceService.updateSysSimDevice(sysSimDevice));
    }

    /**
     * 删除自助设备
     */
    @PreAuthorize("@ss.hasPermi('machine:manage:remove')")
    @Log(title = "自助设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceIds}")
    public AjaxResult remove(@PathVariable Long[] deviceIds)
    {
        return toAjax(sysSimDeviceService.deleteSysSimDeviceByDeviceIds(deviceIds));
    }
}
